package com.chineseall.app.dao.mongo;

import java.util.Date;

import org.bson.types.ObjectId;
import org.springframework.stereotype.Repository;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * 机器对应表
 * _id :机器对应id
 * mid: 机器唯一编码
 * lat: 纬度
 * lon:经度
 * uid:
 * utype: 2,Android、3,IPhone
  "model", 型号;
channel", 渠道
ver: 版本
t: 最后登陆时间
 * @author weibo-xie
 * 2012-6-25
 */
@Repository
public class AppMachine extends AppMongo {

    public DBObject getMachine(String mid) {
        return this.findOne(builder("mid", mid).get());
    }

    public ObjectId getMachineId(String mid) {
        DBObject one = getColl().findOne(builder("mid", mid).get(), builder(ID, ONE).get());
        if (one != null) {
            return (ObjectId) one.get(ID);
        }
        return null;
    }

    public static void main(String[] args) {
        AppMachine coll = new AppMachine();
        BasicDBObject o = new BasicDBObject();
        o.put("mid", "abcdeg");
        o.put("ver", "1.0");
        o.put("d", new Date());
        coll.save(o);

        System.out.println(o.getObjectId("_id"));
        BasicDBObject o2 = new BasicDBObject();
        o2.put(ID, o.getObjectId(ID));
        o2.put("mid", "abcdeg");
        o2.put("ver", "2.0");
        o2.put("t", System.currentTimeMillis());
        coll.save(o2);
    }

}
